package com.rtti;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.IntStream;

/**
 * @program: study
 * @className: RandomList
 * @description: TODO
 * @author: kukuxiahuni
 * @create: 2019-12-04 17:10
 * @version: v1.0
 **/
public class RandomList<T> extends ArrayList<T> {


    public static void main(String[] args) {
        RandomList<String> randomList = new RandomList<>();
        Arrays.stream("The quick brown fox jumped over the lazy brown dog".split(" ")).forEach(randomList::add);
        IntStream.range(0, 14).forEach(i -> System.out.println(randomList.select()));
    }

    /**
     * 功能描述: 随机选择一个元素
     *
     * @param:
     * @return:
     * @auther: kukuxiahuni
     * @date: 2019/12/4 5:11 下午
     * @modify_auther: kukuxiahuni
     * @modify_time: 2019/12/4 5:11 下午
     **/
    public T select() {
        return get(ThreadLocalRandom.current().nextInt(this.size() - 1));
    }

}
